#!/bin/sh
post_dev_save()
{
$DOCUMENT_ROOT/apps/netzone/netzone.sbin dev2lan dev="$FORM_dev" dev_zone="$FORM_lan_zone"
(echo "dev success" | main.sbin output_json 0) || exit 0
}
post_lan_save()
{
$DOCUMENT_ROOT/apps/netzone/netzone.sbin del_dev_forward_firewall_by_src lan_zone="$FORM_lan_zone"
wan_zone_str=`env | grep ^FORM_wan_zone_.*= | awk -F "=" '{print $2}'`
[ -n "$wan_zone_str" ] && for wan_zone in $wan_zone_str
do
$DOCUMENT_ROOT/apps/netzone/netzone.sbin lan2wan lan_zone="$FORM_lan_zone" wan_zone="${wan_zone}"
done
(echo "_LANG_Save_success" | main.sbin output_json 0) || exit 0
}
post_wan_delete()
{
[ "$FORM_netzone" != "wan" ] || (echo "不能删除wan" | main.sbin output_json 1) || exit 1
$DOCUMENT_ROOT/apps/netzone/netzone.sbin delwan dev_zone="$FORM_netzone" 2>&1 >/dev/null
(echo "_LANG_Save_success" | main.sbin output_json 0) || exit 0
}
post_lan_delete()
{
[ "$FORM_netzone" != "lan" ] || (echo "不能删除lan" | main.sbin output_json 1) || exit 1
$DOCUMENT_ROOT/apps/netzone/netzone.sbin dellan dev_zone="$FORM_netzone" 2>&1 >/dev/null
(echo "_LANG_Save_success" | main.sbin output_json 0) || exit 0
}
post_wan_new()
{
[ $FORM_wan_input -eq 1 ] && input_mode="ACCEPT" || input_mode="REJECT"
[ $FORM_wan_output -eq 1 ] && output_mode="ACCEPT" || output_mode="REJECT"
[ $FORM_wan_forward -eq 1 ] && forward_mode="ACCEPT" || forward_mode="REJECT"
[ $FORM_new -eq 1 ] && FORM_wan_zone="wan_$FORM_wan_zone"
$DOCUMENT_ROOT/apps/netzone/netzone.sbin delwan dev_zone="$FORM_wan_zone" 2>&1 >/dev/null
$DOCUMENT_ROOT/apps/netzone/netzone.sbin newwan dev="$FORM_dev" dev_zone="$FORM_wan_zone" input_mode="$input_mode" output_mode="$output_mode" forward_mode="$forward_mode" 2>&1 >/dev/null
(echo "wan Save_success" | main.sbin output_json 0) || exit 0
}
post_lan_new()
{
[ $FORM_lan_input -eq 1 ] && input_mode="ACCEPT" || input_mode="REJECT"
[ $FORM_lan_output -eq 1 ] && output_mode="ACCEPT" || output_mode="REJECT"
[ $FORM_lan_forward -eq 1 ] && forward_mode="ACCEPT" || forward_mode="REJECT"
[ $FORM_new -eq 1 ] && FORM_lan_zone="lan_$FORM_lan_zone"
lan_if=`uci get network.${FORM_lan_zone}.ifname`
if
[ -n "$FORM_ext_tar" ]
then
ext_zone_str="ext_zone_tar=$FORM_ext_tar"
echo "$FORM_lan_zone" | grep -q "^ext_" || FORM_lan_zone="ext_$FORM_lan_zone"
fi
$DOCUMENT_ROOT/apps/netzone/netzone.sbin dellan dev_zone="$FORM_lan_zone" 2>&1 >/dev/null
$DOCUMENT_ROOT/apps/netzone/netzone.sbin newlan $ext_zone_str dev_zone="$FORM_lan_zone" input_mode="$input_mode" output_mode="$output_mode" forward_mode="$forward_mode" zone_ip="$FORM_lan_ip" zone_mask="$FORM_lan_netmask"
[ -n "$lan_if" ] && $DOCUMENT_ROOT/apps/netzone/netzone.sbin dev2lan dev="$lan_if" dev_zone="$FORM_lan_zone"
(echo "_LANG_Save_success" | main.sbin output_json 0) || exit 0
}

get_netzone_status()
{
zonename=$FORM_zonename
[ -z "$zonename" ] && echo '{"status": 1,"msg": "Missing zonename"}' && exit 1
printf "Content-Type: text/html; charset=utf-8\r\n"
printf "\r\n"
ubus call network.interface status '{ "interface": "'$zonename'" }'
}
get_netzone_setting()
{
zonename=$FORM_zonename
[ -z "$zonename" ] && echo '{"status": 1,"msg": "Missing zonename"}' && exit 1
netzone_str=`uci show network.$zonename | grep -v "=interface" | sed "s/^network.[0-9a-zA-z|_]*\.//"`
. /usr/share/libubox/jshn.sh
json_init
for key in `echo "$netzone_str" | sed 's/=.*//'`
do
json_add_string ${key} $(echo "$netzone_str" | grep "${key}=" | cut -d "=" -f2)
done
printf "Content-Type: text/html; charset=utf-8\r\n"
printf "\r\n"
json_dump
}
get_netzones()
{
[ -z "$FORM_zonetype" ] && echo '' && echo '{"status": 1,"msg": "Miss zonetype"}' && exit 1
zonetype=$FORM_zonetype
. /usr/share/libubox/jshn.sh
json_init
json_add_array $zonetype
for zone in `$DOCUMENT_ROOT/apps/netzone/netzone.sbin list_available_${zonetype}zone`
do
json_add_string "" "${zone}"
done
echo ''
json_dump
}
